<template>
	<div>
		<!-- 运单上传回单提示窗 -->
		<uni-popup ref="uploadReceiptDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认上传" :title="formData.receiptAttachments?'重新上传':'上传回单'"
				@confirm="uploadReceiptDialogConfirm" :before-close="true" @close="closeDialog('uploadReceiptDialog')">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 300px;">
					<uni-forms ref="form" :modelValue="formData"  labelWidth="75px">
						<uni-forms-item label="相关资料">
							<!-- <myfilepicker  @clickFile="clickFile_receiptAttachments" limit="3" :imageStyles="imageStyles"  :value="fileList_receiptAttachments" file-extname="png,jpg,jpeg" file-mediatype="image" @select="selectFile_receiptAttachments"  @delete='deleteFile_receiptAttachments' @success="success_receiptAttachments" @fail="fail_receiptAttachments"
								title="*点击上传回单，支持常规图片、PDF、DOC、XLS格式，最多可上传3个附件*"><uni-icons type="cloud-upload" size="18"></uni-icons>回单照片</myfilepicker> -->
						    <myfilepicker :limit="'3'" :imageStyles="imageStyles" :fileIdString="formData.receiptAttachments" :fileExtname="'png,jpg,jpeg'" :fileMediatype="'image'"  @transFileIdString="getFileIdString_receiptAttachments"
						    		:title="'*点击上传回单，支持png/jpg/jpeg，最多可上传3个附件*'"><uni-icons type="cloud-upload" size="18"></uni-icons>回单照片</myfilepicker>
						</uni-forms-item>
					</uni-forms>
					<view style="height: 50px;"></view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {
		uploadReceipt,
	} from '@/api/system/waybill.js'
	import myfilepicker from '@/components/uploadFile/uploadFile.vue'
	export default {
		components: {
			myfilepicker
		},
		props: {
			data: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				formData:{
					receiptAttachments:''
				},
				imageStyles: {
					width: '100%',
					height: 150,
					border: {
						radius: '4px'
					}
				}
			}
		},
		watch: {
			data: {
			　　handler(newValue, oldValue) {
			　　　	this.formData=newValue
			　　},
			　　deep: true
			},
		},
		methods: {
			//关闭弹窗
			closeDialog(name){
				this.$refs[name].close()
				this.formData.receiptAttachments=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_receiptAttachments(fileIds){
				this.formData.receiptAttachments=fileIds
			},
			//上传回单
			uploadReceipt(){
				this.$refs.uploadReceiptDialog.open()
			},
			//确认上传回单
			uploadReceiptDialogConfirm(){
				//文件 (回单)
				if(!this.formData.receiptAttachments)
				{
					uni.showToast({
						icon:'none',
						title:'请至少上传1份回单'
					})
					return
				}
				
				uni.showLoading({
					title: '正在上传...',
				})
				
				//上传回单
				uploadReceipt({
					waybillId:this.formData.waybillId,
					receiptAttachments:this.formData.receiptAttachments
				}).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '上传成功',
							icon: 'none'
						})
						this.$refs.uploadReceiptDialog.close()
						this.$parent.init()  //调用父组件的init函数，重新加载数据
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}	
				})
			},
		},
	}
</script>

<style scoped>

</style>